<?php
namespace app\common\config\model;


use app\common\config\logic\RegionLogic;
use think\Model;
use think\model\concern\SoftDelete;

class ConfigStore extends Model
{
    use SoftDelete;
    protected $defaultSoftDelete = 0;

    protected $type = [
        // 'coordinate' => 'point',
    ];

    public function setTagsAttr($value) {
        return json_encode($value);
    }

    public function getTagsAttr($value) {
        return json_decode($value, true);
    }

    /**
     * 设置专辑属性
     * @return string
     */
    public function setAlbumAttr($value): string
    {
        return json_encode($value);
    }

    /**
     * 获取专辑属性
     * @return array
     */
    public function getAlbumAttr($value): array
    {
        return json_decode($value, true);
    }

    /**
     * 设置坐标点，point类型
     * $value = lng,lat
     * @return string
     */
    public function setCoordinateAttr($value): string
    {
        return trim($value);
    }

    public function getBusinessCategoryAttr($value) {
        return explode(',', $value);
    }

    public function setBusinessCategoryAttr($value): string
    {
        return implode(',', $value);
    }

    public function getZoneAttr($value, $data) {
        $logic = new RegionLogic();
        $zone = $logic->getRegion($data['zone_id']);
        return $zone ? $zone['name'] : '上海市';
    }
}